package org.aldar.bquest.screens;

import android.content.Intent;
import org.aldar.bquest.util.SQLiteHelper;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.Entity;
import org.andengine.entity.scene.IOnSceneTouchListener;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;

import java.io.IOException;


/**
 * User: Daria
 * Date: 1/14/14 11:16 PM
 */
public class LevelFailedScreen extends ScreenWithInterstitialBanner implements IOnSceneTouchListener {

    private static final int CAMERA_WIDTH = 480;
    private static final int CAMERA_HEIGHT = 800;

    private Entity bgLayer;

    protected Camera mCamera;

    protected Scene scene;


    private SQLiteHelper mSQLiteHelper = new SQLiteHelper(this);

    private BitmapTextureAtlas bgTexture;
    protected TextureRegion bgTextureRegion;


    @Override
    public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    protected void onCreateResources() throws IOException {
        this.bgTexture = new BitmapTextureAtlas(getTextureManager(), 480, 800, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.bgTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.bgTexture, this, "gfx/skillselection/screen_ability.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.bgTexture);
    }

    @Override
    protected Scene onCreateScene() {
        //场景
        this.scene = new Scene(2);

        bgLayer = new Entity();
        scene.attachChild(bgLayer);

        this.init();
        return this.scene;
    }

    private void init() {
        final Sprite bg = new Sprite(0, 0, this.bgTextureRegion, getVertexBufferObjectManager());
        bg.setAnchorCenter(0, 0);
        this.bgLayer.attachChild(bg);

    }

    @Override
    public EngineOptions onCreateEngineOptions() {
        mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        EngineOptions opts = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED,
                new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
        opts.getAudioOptions().setNeedsSound(true);
        opts.getRenderOptions().setDithering(true);
        return opts;
    }


    private void showLevelMap() {
        Intent intent = new Intent();
        intent.setClass(this.getApplicationContext(), LevelMapScreen.class);
        startActivity(intent);
        this.finish();
    }


    @Override
    public boolean isBannerEnabled() {
        return true;
    }
}
